<template>
  <el-row :gutter="10" class="container">
    <el-col :span="6">
      <el-button type="info">原负责人：{{ oldOwnerUsername }}</el-button>
    </el-col>
    <el-col :span="6">
      <el-button type="primary">
        <i class="el-icon-caret-right"></i>
      </el-button>
    </el-col>
    <el-col :span="6">
      <SelectUsers v-model="OwnerUsername" :exclude="oldOwnerUsername"></SelectUsers>
    </el-col>
    <el-col :span="6">
      <el-button type="primary" icon="el-icon-success" @click="handleAssign"
        >确认指派</el-button
      >
    </el-col>
  </el-row>
</template>

<script>
import SelectUsers from "./SelectUsers.vue";
export default {
  components:{SelectUsers},
  props: {
    currentCust: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      users: [],
      newOwnerUsername: "",
      oldOwnerUsername: this.currentCust.ownerUsername,
    };
  },
  methods: {
    handleAssign() {
        this.axios
        .put(`customer/assign/${this.currentCust.custId}/${this.newOwnerUsername}`)
        .then(() => {
            this.$message.success("用户指派成功");
            this.currentCust.ownerUsername = this.newOwnerUsername;
        })
        .catch(() => {
            this.$message.error("用户指派失败");
        })
    },
  },
};
</script>

<style scoped>
.container {
  text-align: center;
}
</style>